package com.yinuo.quartz;

import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Calendar;

@Configuration
public class QuartzConfig {
    @Bean
    public JobDetail fileClearQuartzDetail(){
        return JobBuilder.newJob(FileClearQuartz.class).withIdentity("fileClearQuartz").storeDurably().build();
    }

    @Bean
    public Trigger fileClearQuartzTrigger(){
        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
                .withIntervalInMinutes(30)  //设置时间周期单位分钟，30分钟清理一次
                .repeatForever();

        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.SECOND, 5);   //5秒之后的时间
        return TriggerBuilder.newTrigger().forJob(fileClearQuartzDetail())
                .startAt(calendar.getTime())
                .withIdentity("fileClearQuartz")
                .withSchedule(scheduleBuilder)
                .build();
    }
}